package com.bishe.cyh.utils;

import com.bishe.cyh.mode.Dataji;
import com.bishe.cyh.mode.TaskSubmit;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * @Author: Poppin
 * @Date: 2022/2/28 16:51
 * @Version: 1.0
 */
@Component
public class ListSort {

    public static void TaskList(List<TaskSubmit> list){
        Collections.sort(list, new Comparator<TaskSubmit>() {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            @Override
            public int compare(TaskSubmit o1, TaskSubmit o2) {
                try{
                    Date date1 = simpleDateFormat.parse(o1.getStarttime());
                    Date date2 = simpleDateFormat.parse(o2.getStarttime());
                    if (date1.getTime()<date2.getTime()){
                        return 1;
                    }else if (date1.getTime()>date2.getTime()){
                        return -1;
                    }else {
                        return 0;
                    }
                }catch (Exception e){

                }
                return 0;
            }
        });
    }

    public static void DataList(List<Dataji> list){
        Collections.sort(list, new Comparator<Dataji>() {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            @Override
            public int compare(Dataji o1, Dataji o2) {
                try{
                    Date date1 = simpleDateFormat.parse(o1.getTime());
                    Date date2 = simpleDateFormat.parse(o2.getTime());
                    if (date1.getTime()<date2.getTime()){
                        return 1;
                    }else if (date1.getTime()>date2.getTime()){
                        return -1;
                    }else {
                        return 0;
                    }
                }catch (Exception e){

                }
                return 0;
            }
        });
    }
}
